'''
Bank account system project
1. Login
2. Show Balance
3. Withdraw
4. Deposit
5. Exit
'''
# Account information database (type dict)
accInfo = {
    '0001':{'name': 'Apple','balance':1000.0, 'pwd':'1234'},
    '0002':{'name': 'Orange','balance':1000.0, 'pwd':'1234'},
    '0003':{'name': 'Pear','balance':1000.0, 'pwd':'1234'}}

def acc_balance(accID):
    '''
        To show the account balance
    param accID: account number
    '''
    if not accID in accInfo:
        input("Incorrect account Number. Press ENTER key to continue ...")
        return

    print('{:=^50}'.format('Account Information'))
    print('|{:<10}|{:^15}|{:^15}|'.format('Acc ID','Name','Balance'))
    print('-'*40)
    print('|{:<10}|{:<15}|{:^15}|'.format(accID, accInfo[accID]['name'], accInfo[accID]['balance']))

    input('Press ENTER key to return ... ')
    return

def acc_withdraw(accID, amount):
    '''
        To withdraw money from the account 
    param accID: account number, type string
    param amount: amount of money to withdraw, type float
    '''
    if not accID in accInfo:
        input("Incorrect account Number. Press ENTER key to continue ...")
        return -1

    balance = accInfo[accID]['balance']
    if balance < amount:
        input("Not enough money. Withdraw cancelled. Press ENTER key to continue ...")
        return -1
    else:
        accInfo[accID]['balance'] = balance - amount
        print("Withdraw succeed.\n The account balance is: {}".format(accInfo[accID]['balance']))
        input("Press ENTER key to continue ...")
                
    return 0
        
def acc_deposit(accID, amount):
    '''
        To deposit money to the account 
    param accID: account number, type string
    param amount: amount of money to withdraw, type float
    '''
    if not accID in accInfo:
        input("Incorrect account Number. Press ENTER key to continue ...")
        return -1

    balance = accInfo[accID]['balance']
    accInfo[accID]['balance'] = balance + amount
    print("Deposit succeed.\n The account balance is: {}".format(accInfo[accID]['balance']))
    input("Press ENTER key to continue ...")
                
    return 0

def enter_subsystem(accID):
    ''' Customer dialog
    :param accID: account ID
    :return:
    '''
    while True:
        #Print Title bar
        print('\n{:=^50}'.format(" Banking Account System "))
        print('\t1.{:<25}\t2.{:<25}'.format("Show Balance", "Withdraw"))
        print('\t3.{:<25}\t4.{:<25}'.format("Deposit", "Logout"))
        print('=' * 50)

        option = input("Please input your option: ")
        if option == '1':
            acc_balance(accID)
        elif option == '2':
            acc_withdraw(accID, float(input("Please input the amount to withdraw: ")))
        elif option == '3':
            acc_deposit(accID, float(input("Please input the amount to deposit: ")))
            pass
        elif option == '4':
            print("Logout ...Done!")
            break
        else:
            print("Incorrect option!")
    return

'''
Main Dialog
'''
while True:
    # Login or Exit
    print('\n{:=^50}'.format(" Banking Account System "))
    print('\t1.{:<25}\t2.{:<25}'.format("Login", "Exit"))

    option = input("Please input your option: ")
    if option == '1':
        accID = input("Please input your account ID: (eg.0001): ")
        pwd = input("Please input your password (e.g. 1234): ")
        if accID in accInfo:
            if pwd == accInfo[accID]["pwd"]:
                enter_subsystem(accID)
            else:
                input("Incorrect Password! Press ENTER key to continue ...")
        else:
            input("Incorrect Account Number! Press ENTER key to continue ...")
    elif option == '2':
        break
